package god.dream.notice.controller;

import god.dream.notice.model.Notice;
import god.dream.notice.service.NoticeService;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class NoticeNotFormController extends MultiActionController {
	@Autowired
	private NoticeService noticeService;

	public ModelAndView listNotices(HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		List<Notice> noticeList = noticeService.findNoticeList();
		ModelAndView mav = new ModelAndView("list_notices");
		mav.addObject("notices", noticeList);
		return mav;
	}
	public ModelAndView deleteNotice(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		if(id != null)
			noticeService.removeNotice(Integer.parseInt(id));
		ModelAndView mav = new ModelAndView("redirect:/cont/listUsers.htm");
		return mav;
	}
	public ModelAndView selectNotice(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String id = request.getParameter("id");
		Notice notice = new Notice();
		if(id != null)
			notice = noticeService.findNotice(Integer.parseInt(id));
		ModelAndView mav = new ModelAndView("select_notice");
		mav.addObject("notice", notice);
		return mav;
	}
	public NoticeService getNoticeService() {
		return noticeService;
	}
	public void setNoticeService(NoticeService noticeService) {
		this.noticeService = noticeService;
	}
}
